//
//  FirstPhotoDetailsViewController.m
//  艾听歌
//
//  Created by dllo on 16/5/30.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FirstPhotoDetailsViewController.h"

#import "ModuleFirst_UserLoveModel.h"


#import "TravelsPhotoDetailsView.h"



#define ViewW self.view.frame.size.width
#define ViewH self.view.frame.size.height


@interface FirstPhotoDetailsViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *AllphotoScrollView;

@property (nonatomic, strong) NSMutableDictionary *allPhotoIdDic;

@property (nonatomic, strong) UIScrollView *bigScrollView;



@end

@implementation FirstPhotoDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
    self.view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9c9c9c);
    self.navigationController.navigationBar.dk_barTintColorPicker = DKColorPickerWithRGB(0xFF6EB4, 0x9C9C9C);
  
    
    self.allPhotoIdDic = [NSMutableDictionary dictionary];
    
    
    //将照片的id和其在数组的下标(字符串,要用再转)一一对应
    for (int i = 0; i < self.allPhotoArray.count; i++) {
        
        ModuleFirst_UserLoveModel *MF_ULModel = self.allPhotoArray[i];
        [self.allPhotoIdDic setObject:[NSString stringWithFormat:@"%d",i] forKey:MF_ULModel.idd ];
    }
    
    //定义bigScrollView
    self.bigScrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
//    self.bigScrollView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.bigScrollView];
    
    //可以横向滑动的距离
    self.bigScrollView.contentSize = CGSizeMake(ViewW * self.allPhotoArray.count, 0);
    //是否整页滑动
    self.bigScrollView.pagingEnabled = YES;
    //是否关闭横向滑动条
//    self.bigScrollView.showsHorizontalScrollIndicator = NO;
    //是否关闭回弹效果
    self.bigScrollView.bounces = NO;
    
    //成为代理人
    self.bigScrollView.delegate = self;
    
    
    
    for (int i = 0; i < self.allPhotoArray.count; i++) {
        
        
        TravelsPhotoDetailsView *smallView = [[TravelsPhotoDetailsView alloc]initWithFrame:CGRectMake(ViewW * i, 0, ViewW, ViewH)];
        smallView.backgroundColor = [UIColor whiteColor];
        smallView.photoDetailModel = self.allPhotoArray[i];
        
        __block FirstPhotoDetailsViewController *root = self;
        smallView.backToUserHomepage = ^(){
            
            [root dismissViewControllerAnimated:YES completion:^{
                
                
            }];
            
        };
        
        [self.bigScrollView addSubview:smallView];
        
        
    }
    
    //第一个显示的照片
    NSString *photoId = [self.allPhotoIdDic objectForKey:self.selectedPhotoModel.idd ];
//    NSLog(@"%@",photoId);
    self.bigScrollView.contentOffset = CGPointMake(ViewW * [photoId floatValue], 0);

    
}


//滚动结束
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    //滑动结束后各个子Scroll的缩放程度为1.0
    for (UIScrollView *small in scrollView.subviews) {
        if ([small isKindOfClass:[UIScrollView class]]) {
            small.zoomScale = 1.0;
            //滑动结束后各个子Scroll中的照片尺寸恢复满屏大小
            UIView *isImageView = [small.subviews firstObject];
            isImageView.frame = CGRectMake(0, 0, ViewW , ViewH);
        }
    }

}




@end
